#include <iostream>
#include <cmath>

using namespace std;

double values[3][7][15] = {
    { // class A
        {18, 17, 15, 16, 19, 15, 17, 18, 18, 14, 17, 15, 18, 16, 15}, // 1 
        {19, 16, 12, 11, 17, 18, 13, 11, 15, 16, 19, 17, 12, 13, 11}, // 2
        {22, 26, 38, 32, 24, 22, 34, 36, 26, 22, 30, 32, 38, 34, 24}, // 3
        {55, 56, 57, 57, 57, 59, 60, 60, 61, 62, 62, 63, 63, 64, 65}, // 4
        {35, 34, 30, 32, 37, 30, 33, 36, 35, 28, 33, 30, 35, 32, 29}, // 5
        {17, 18, 13, 19, 16, 12, 11, 17, 18, 13, 11, 15, 16, 19, 17}, // 6
        {11, 13, 19, 16, 12, 11, 17, 18, 13, 11, 15, 16, 19, 17, 12}  // 7
    },
    { // class B
        {27, 28, 25, 29, 24, 27, 22, 26, 27, 21, 25, 23, 26, 22, 24},
        {15, 16, 19, 17, 13, 19, 16, 12, 16, 16, 12, 11, 17, 18, 13},
        {26, 22, 30, 32, 39, 34, 26, 38, 32, 24, 22, 34, 36, 22, 28},
        {37, 38, 39, 39, 41, 41, 42, 42, 43, 44, 44, 45, 45, 46, 47},
        {53, 55, 50, 57, 47, 54, 43, 51, 55, 41, 49, 46, 52, 43, 47},
        {12, 19, 16, 12, 11, 17, 18, 13, 11, 15, 16, 19, 17, 12, 13},
        {13, 11, 15, 16, 19, 17, 13, 19, 16, 12, 11, 17, 18, 11, 14}
    },
    { // class C
        {30, 28, 32, 26, 30, 28, 31, 33, 25, 29, 27, 27, 26, 30, 28},
        {11, 15, 16, 19, 17, 12, 13, 11, 15, 16, 17, 17, 13, 19, 16},
        {34, 26, 38, 32, 24, 22, 34, 36, 22, 28, 26, 26, 38, 34, 24},
        {51, 52, 52, 53, 53, 54, 54, 54, 55, 56, 56, 57, 58, 58, 59},
        {60, 56, 64, 52, 59, 55, 61, 65, 50, 58, 63, 54, 51, 60, 56},
        {11, 15, 16, 19, 17, 13, 19, 16, 12, 11, 118, 18, 17, 18, 13},
        {17, 13, 19, 16, 12, 11, 17, 18, 11, 14, 13, 13, 19, 17, 12}
    }
};

int get_defenition(double coefficients[3], double x1, double x2, double constant){
    double G_linear_expression = coefficients[2] + coefficients[1] * x1 + coefficients[0] * x2;
    return G_linear_expression < constant ? 0 : 1;
}

char defenition_class(double x1, double x2){
    char result_class = '0';

    double AB_coefficients[3] = {0.010952713117589, -0.040892887947431, 2.14392444421283};
    double AC_coefficients[3] = {0.075390119230278, 0.022640116801489, -3.68327143040671};
    double BC_coefficients[3] = {0.023532512527987, 0.059177700657227, -2.62953475259866};

    double AB_const = 0.5;
    double AC_const = 0.995257956635296;
    double BC_const = 1.5;

    int AB;
    int AC;
    int BC;

    AB = get_defenition(AB_coefficients, x1, x2, AB_const);
    AC = get_defenition(AC_coefficients, x1, x2, AC_const);
    BC = get_defenition(BC_coefficients, x1, x2, BC_const);

    if (AB == 0 && AC == 0){
        result_class = 'A';
    }
    
    if (AB == 1 && BC == 0){
        result_class = 'B';
    }

    if (AC == 1 && BC == 1){
        result_class = 'C';
    }

    return result_class;
}

void objects_test(double values[3][7][15]){
    char result;
    int count_errors = 0;

    for (int i = 0; i < 15; i++){
        result = defenition_class(values[0][3][i], values[0][4][i]);

        if (result == 'A'){
            cout << "✅ Yes, object has class:" << result << endl;
        }
        else {
            count_errors++;
            cout << "❌ No, object has class:" << result << endl;
        }
    }

    cout << endl;

    for (int i = 0; i < 15; i++){
        result = defenition_class(values[1][3][i], values[1][4][i]);

        if (result == 'B'){
            cout << "✅ Yes, object has class:" << result << endl;
        }
        else {
            count_errors++;
            cout << "❌ No, object has class:" << result << endl;
        }
    }

    cout << endl;

    for (int i = 0; i < 15; i++){
        result = defenition_class(values[2][3][i], values[2][4][i]);

        if (result == 'C'){
            cout << "✅ Yes, object has class:" << result << endl;
        }
        else {
            count_errors++;
            cout << "❌ No, object has class:" << result << endl;
        }
    }

    cout << "\nErrors count: " << count_errors << endl;
}

int main(){
    objects_test(values);

    return 0;
}